﻿Imports System.Collections.Specialized
Public Class ListForm

    Private _SQL As String = ""
    Public Property SQL() As String
        Get
            Return _SQL
        End Get
        Set(ByVal value As String)
            _SQL = value
        End Set
    End Property

    Private _显示列 As StringCollection
    Public Property 显示列() As StringCollection
        Get
            Return _显示列
        End Get
        Set(ByVal value As StringCollection)
            _显示列 = value
        End Set
    End Property

    Private _返回值 As New StringCollection
    Public Property 返回值() As StringCollection
        Get
            Return _返回值
        End Get
        Set(ByVal value As StringCollection)
            _返回值 = value
        End Set
    End Property

    Private Sub ListForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dt As DataTable = ct.FillTable(SQL)
        Me.DataGridView1.AutoGenerateColumns = True
        Me.DataGridView1.DataSource = dt
        For Each cl As DataGridViewColumn In Me.DataGridView1.Columns
            If 显示列.Contains(cl.Name) Then
                cl.Visible = True
            Else
                cl.Visible = False
            End If
        Next
        Dim width As Integer = 0
        For i As Integer = 0 To Me.DataGridView1.ColumnCount - 1
            If Me.DataGridView1.Columns(i).Visible = True Then
                width += Me.DataGridView1.Columns(i).Width
            End If
        Next
        Me.Width = width + 40
    End Sub

    Private Sub DataGridView1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick
        If DataGridView1.RowCount > 0 AndAlso DataGridView1.SelectedRows.Count > 0 Then
            For i As Int16 = 0 To DataGridView1.Columns.Count - 1
                返回值.Add(DataGridView1.SelectedRows(0).Cells(i).Value.ToString())
            Next
        End If
        Me.Close()
    End Sub
End Class
